
#include "stdafx.h"
#include "ttg/pipeline.h"

using namespace ttg::pipeline;

//Checks positiveness of incoming float.
class IsPositive :public Node<float, bool>
{
	protected:
		virtual void process(float data)
				{ this->sendNext( data > 0.0f); }
};

//Checks negativeness of incoming float.
class IsNegative :public Node<float, bool>
{
	protected:
		virtual void process(float data)
				{ this->sendNext( data < 0.0f); }
};

//Applies || operation for incoming pair of bool.
class Or :public Node<bool, bool>
{
	private:
		bool res;
	protected:
		//Clears "res" from previous iteration.
		virtual void onBegin()
				{ res = false; }
		//Sends result to next node.
		virtual void onEnd()
				{ this->sendNext(res); }
		virtual void process(bool data)
				{ res |= data; }
	public:
		inline Or()
			:Node("Or", true)
		{ /*nothing*/ }
};

//Inverses incoming bool.
class Not :public Node<bool, bool>
{
	protected:
		virtual void process(bool data)
				{ sendNext(!data); }
};

int _tmain(int argc, _TCHAR* argv[])
{
	ttg::services::ServiceBase::getRef()->start();
	//Creating pipeline.
	Pipeline<float, bool> isZero(wrap(new IsPositive()) * wrap(new IsNegative()) +
								 wrap(new Or()) + wrap(new Not()));
	PipelineLogger logger("123.log");
	//Testing.
	if (!isZero.run(0.0f)[0])
		printf("0.0f != 0.0f"); else
	if (isZero.run(1.0f)[0])
		printf("1.0f == 0.0f"); else
	if (isZero.run(-1.0f)[0])
		printf("-1.0f == 0.0f");
	else
		printf("It works!\n");
	return 0;
}
